import java.applet.AudioClip;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;
import java.sql.*;
import java.util.Arrays;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JFrame;

import org.iforce2d.Jb2dJson;
import org.iforce2d.Jb2dJsonImage;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.World;

import com.microsoft.sqlserver.jdbc.*;

public class DatabaseManager {
	
	private static DatabaseManager databaseManagerInstance;
	
	public static void create(){
		
		
	}
	
	

	private DatabaseManager() {
		
	}

	public static DatabaseManager createDatabaseManager() {
		if( databaseManagerInstance == null )
		{
			databaseManagerInstance = new DatabaseManager();
			return databaseManagerInstance;
		}
		else
		{
			return databaseManagerInstance;
		}
		
	}

	public LevelWorld getLevelData(String username) throws IOException {
		int levelNo = 0;
		// Connection string for your SQL Database server.
		// Change the values assigned to your_server, 
		// your_user@your_server,
		// and your_password.
		String connectionString = 
		    "jdbc:sqlserver://cwknc6b9er.database.windows.net:1433;" +
		    "database=MortarCombatDB;user=firat@cwknc6b9er;password={Mortar_123};" +
		    "encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

		// The types for the following variables are
		// defined in the java.sql library.
		Connection connection = null;  // For making the connection
		Statement statement = null;    // For the SQL statement
		
		ResultSet resultSet = null;    // For the result set, if applicable
		

		try
		{
		    // Ensure the SQL Server driver class is available.
		    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

		    // Establish the connection.
		    connection = DriverManager.getConnection(connectionString);

		    // Define the SQL string.
		    String sqlString = "SELECT [LastEpisode] FROM UserTable WHERE Name= '"+username+"'";
		    String sqlString2 = "";

		    // Use the connection to create the SQL statement.
		    statement = connection.createStatement();
		    

		    // Execute the statement.
		    resultSet = statement.executeQuery(sqlString);
		    

		    // Loop through the results

		    while (resultSet.next())
		    {
				    	
				    String lastEp = resultSet.getString("LastEpisode");
				    
				    levelNo = Integer.parseInt(lastEp);
				        
				        
			}
   				    			    
		    // Provide a message when processing is complete.
		   

		}
		catch (ClassNotFoundException cnfe)  
        {

            System.out.println("ClassNotFoundException " +
                               cnfe.getMessage());
        }
        catch (Exception e)
        {
            System.out.println("Exception " + e.getMessage());
            e.printStackTrace();
        }
        finally
        {
            try
            {
                // Close resources.
                if (null != connection) connection.close();
                if (null != statement) statement.close();
                if (null != resultSet) resultSet.close();
            }
            catch (SQLException sqlException)
            {
                // No additional action if close() statements fail.
            }
        }
		
		return createLevelData( levelNo );
	}

	public LevelWorld getLevelData(int levelNo) throws IOException {
		return createLevelData( levelNo );
	}

	
	/*
	 * 			Settings[0]= lastEpisode;
		    	Settings[1]= volume;
		    	Settings[2]= music;
		    	Settings[3]= score;
		    	Settings[4] = difficulty;
	 */
	public int[] getSettings(String username) {

		int Settings[] = new int[4];
		
		// Connection string for your SQL Database server.
		// Change the values assigned to your_server, 
		// your_user@your_server,
		// and your_password.
		String connectionString = 
		    "jdbc:sqlserver://cwknc6b9er.database.windows.net:1433;" +
		    "database=MortarCombatDB;user=firat@cwknc6b9er;password={Mortar_123};" +
		    "encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

		// The types for the following variables are
		// defined in the java.sql library.
		Connection connection = null;  // For making the connection
		Statement statement = null;    // For the SQL statement
		
		ResultSet resultSet = null;    // For the result set, if applicable
		

		try
		{
		    // Ensure the SQL Server driver class is available.
		    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

		    // Establish the connection.
		    connection = DriverManager.getConnection(connectionString);

		    // Define the SQL string.
		    String sqlString = "SELECT [LastEpisode], [VolumeSetting], [MusicSeting], [Score], [Difficulty] FROM UserTable WHERE Name='"+username+"'";
		    

		    // Use the connection to create the SQL statement.
		    statement = connection.createStatement();
		    

		    // Execute the statement.
		    resultSet = statement.executeQuery(sqlString);
		    

		    // Loop through the results
		  
		    
		   
		    		
		    		resultSet.next();
				    				    	
				    	String sco = resultSet.getString("Score");
				    	String lastEp = resultSet.getString("LastEpisode");
				    	String vol = resultSet.getString("VolumeSetting");
				    	String mus = resultSet.getString("MusicSeting");   
				    	String diff = resultSet.getString("Difficulty");
				    
		    	int score = Integer.parseInt(sco);
		    	int lastEpisode = Integer.parseInt(lastEp);
		    	int volume = Integer.parseInt(vol);
		    	int music = Integer.parseInt(mus);
		    	int difficulty = Integer.parseInt(diff);
		    	
		    	Settings[0]= lastEpisode;
		    	Settings[1]= volume;
		    	Settings[2]= music;
		    	Settings[3]= score;
		    	Settings[4] = difficulty;
   				    			    
		    // Provide a message when processing is complete.
		   

		}
		catch (ClassNotFoundException cnfe)  
        {

            System.out.println("ClassNotFoundException " +
                               cnfe.getMessage());
        }
        catch (Exception e)
        {
            System.out.println("Exception " + e.getMessage());
            e.printStackTrace();
        }
        finally
        {
            try
            {
                // Close resources.
                if (null != connection) connection.close();
                if (null != statement) statement.close();
                if (null != resultSet) resultSet.close();
            }
            catch (SQLException sqlException)
            {
                // No additional action if close() statements fail.
            }
        }
		return Settings;
	}

	public String[][] getHighScores() {
		
		String highScores[][] = new String[10][2];
		
		// Connection string for your SQL Database server.
		// Change the values assigned to your_server, 
		// your_user@your_server,
		// and your_password.
		String connectionString = 
		    "jdbc:sqlserver://cwknc6b9er.database.windows.net:1433;" +
		    "database=MortarCombatDB;user=firat@cwknc6b9er;password={Mortar_123};" +
		    "encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

		// The types for the following variables are
		// defined in the java.sql library.
		Connection connection = null;  // For making the connection
		Statement statement = null;    // For the SQL statement
		
		ResultSet resultSet = null;    // For the result set, if applicable
		

		try
		{
		    // Ensure the SQL Server driver class is available.
		    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

		    // Establish the connection.
		    connection = DriverManager.getConnection(connectionString);

		    // Define the SQL string.
		    String sqlString = "SELECT [Name], [Score] FROM UserTable ORDER BY Score desc";
		    String sqlString2 = "";

		    // Use the connection to create the SQL statement.
		    statement = connection.createStatement();
		    

		    // Execute the statement.
		    resultSet = statement.executeQuery(sqlString);
		    

		    // Loop through the results
		  
		    
		   
		    		int i=0;
		    		int k=0;
		    		while (resultSet.next())
				    {
				    	
				    	String score = resultSet.getString("Score");
				    	String name = resultSet.getString("Name");
				    	highScores[i][k] = name;
				    	highScores[i][k+1] = score;
				    	i = i+1;
				    	k =0;
				    	
				        
				        
				    }
   				    			    
		    // Provide a message when processing is complete.
		   

		}
		catch (ClassNotFoundException cnfe)  
        {

            System.out.println("ClassNotFoundException " +
                               cnfe.getMessage());
        }
        catch (Exception e)
        {
            System.out.println("Exception " + e.getMessage());
            e.printStackTrace();
        }
        finally
        {
            try
            {
                // Close resources.
                if (null != connection) connection.close();
                if (null != statement) statement.close();
                if (null != resultSet) resultSet.close();
            }
            catch (SQLException sqlException)
            {
                // No additional action if close() statements fail.
            }
        }
		
		return highScores;
		


	}

	public void changeMusicVolume(String username, int amount) {
		// Connection string for your SQL Database server.
				// Change the values assigned to your_server, 
				// your_user@your_server,
				// and your_password.
				String connectionString = 
				    "jdbc:sqlserver://cwknc6b9er.database.windows.net:1433;" +
				    "database=MortarCombatDB;user=firat@cwknc6b9er;password={Mortar_123};" +
				    "encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

				// The types for the following variables are
				// defined in the java.sql library.
				Connection connection = null;  // For making the connection
				Statement statement = null;    // For the SQL statement
				
				int resultSet;    // For the result set, if applicable
				

				try
				{
				    // Ensure the SQL Server driver class is available.
				    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

				    // Establish the connection.
				    connection = DriverManager.getConnection(connectionString);

				    // Define the SQL string.
				    String sqlString = " UPDATE UserTable SET [MusicSeting]='"+amount+"' WHERE [Name]='"+username+"'  ";
				   

				    // Use the connection to create the SQL statement.
				    statement = connection.createStatement();
				    

				    // Execute the statement.
				    resultSet = statement.executeUpdate(sqlString);
				    

				  
				   

				}
				catch (ClassNotFoundException cnfe)  
		        {

		            System.out.println("ClassNotFoundException " +
		                               cnfe.getMessage());
		        }
		        catch (Exception e)
		        {
		            System.out.println("Exception " + e.getMessage());
		            e.printStackTrace();
		        }
		        finally
		        {
		            try
		            {
		                // Close resources.
		                if (null != connection) connection.close();
		                if (null != statement) statement.close();
		                
		            }
		            catch (SQLException sqlException)
		            {
		                // No additional action if close() statements fail.
		            }
		        }
		
		
	}

	public static void changeSoundVolume(String username, int amount) {		
		// Connection string for your SQL Database server.
		// Change the values assigned to your_server, 
		// your_user@your_server,
		// and your_password.
		String connectionString = 
		    "jdbc:sqlserver://cwknc6b9er.database.windows.net:1433;" +
		    "database=MortarCombatDB;user=firat@cwknc6b9er;password={Mortar_123};" +
		    "encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

		// The types for the following variables are
		// defined in the java.sql library.
		Connection connection = null;  // For making the connection
		Statement statement = null;    // For the SQL statement
		
		int resultSet;    // For the result set, if applicable
		

		try
		{
		    // Ensure the SQL Server driver class is available.
		    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

		    // Establish the connection.
		    connection = DriverManager.getConnection(connectionString);

		    // Define the SQL string.
		    String sqlString = " UPDATE UserTable SET [VolumeSetting]='"+amount+"' WHERE [Name]='"+username+"'  ";
		   

		    // Use the connection to create the SQL statement.
		    statement = connection.createStatement();
		    

		    // Execute the statement.
		    resultSet = statement.executeUpdate(sqlString);
		    

		  
		   

		}
		catch (ClassNotFoundException cnfe)  
        {

            System.out.println("ClassNotFoundException " +
                               cnfe.getMessage());
        }
        catch (Exception e)
        {
            System.out.println("Exception " + e.getMessage());
            e.printStackTrace();
        }
        finally
        {
            try
            {
                // Close resources.
                if (null != connection) connection.close();
                if (null != statement) statement.close();
                
            }
            catch (SQLException sqlException)
            {
                // No additional action if close() statements fail.
            }
        }
	}

	public boolean checkValidation(String username, String password) {
		
		boolean isValid = true;
		// Connection string for your SQL Database server.
		// Change the values assigned to your_server, 
		// your_user@your_server,
		// and your_password.
		String connectionString = 
		    "jdbc:sqlserver://cwknc6b9er.database.windows.net:1433;" +
		    "database=MortarCombatDB;user=firat@cwknc6b9er;password={Mortar_123};" +
		    "encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

		// The types for the following variables are
		// defined in the java.sql library.
		Connection connection = null;  // For making the connection
		Statement statement = null;    // For the SQL statement
		
		ResultSet resultSet = null;    // For the result set, if applicable
		int resultSetter;
		

		try
		{
		    // Ensure the SQL Server driver class is available.
		    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

		    // Establish the connection.
		    connection = DriverManager.getConnection(connectionString);

		    // Define the SQL string.
		    String sqlString = "SELECT [Name] FROM UserTable";
		    String adder = "INSERT INTO UserTable " + "VALUES (4, '"+username+"', 1, 1, 1, '"+password+"', 0)";
		    

		    // Use the connection to create the SQL statement.
		    statement = connection.createStatement();
		    

		    // Execute the statement.
		    resultSet = statement.executeQuery(sqlString);
		    

		    // Loop through the results
		    
		    
		    while (resultSet.next())
			{
				    	
				    	
		    	String name = resultSet.getString("Name");
				
		    	if(name.equals(username)){
				    		
				    		isValid = false;
				}
				    	
				        
				        
			}
		    
		    if(isValid==true){
		    	resultSetter = statement.executeUpdate(adder);
		    	
		    }
   				    			    
		    // Provide a message when processing is complete.
		   

		}
		catch (ClassNotFoundException cnfe)  
        {

            System.out.println("ClassNotFoundException " +
                               cnfe.getMessage());
        }
        catch (Exception e)
        {
            System.out.println("Exception " + e.getMessage());
            e.printStackTrace();
        }
        finally
        {
            try
            {
                // Close resources.
                if (null != connection) connection.close();
                if (null != statement) statement.close();
                if (null != resultSet) resultSet.close();
            }
            catch (SQLException sqlException)
            {
                // No additional action if close() statements fail.
            }
        }
		
		return isValid;
	}

	public boolean checkUser(String username, String password) {
		boolean isValid = false;
		// Connection string for your SQL Database server.
		// Change the values assigned to your_server, 
		// your_user@your_server,
		// and your_password.
		String connectionString = 
		    "jdbc:sqlserver://cwknc6b9er.database.windows.net:1433;" +
		    "database=MortarCombatDB;user=firat@cwknc6b9er;password={Mortar_123};" +
		    "encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

		// The types for the following variables are
		// defined in the java.sql library.
		Connection connection = null;  // For making the connection
		Statement statement = null;    // For the SQL statement
		
		ResultSet resultSet = null;    // For the result set, if applicable
		
		

		try
		{
		    // Ensure the SQL Server driver class is available.
		    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

		    // Establish the connection.
		    connection = DriverManager.getConnection(connectionString);

		    // Define the SQL string.
		    String sqlString = "SELECT * FROM UserTable";

		    // Use the connection to create the SQL statement.
		    statement = connection.createStatement();
		    

		    // Execute the statement.
		    resultSet = statement.executeQuery(sqlString);
		    

		    // Loop through the results
		    
		    
		    while (resultSet.next())
			{
				    		
		    	
		    	String name = resultSet.getString("Name");
		    	String pass = resultSet.getString("Password");
		    	
		    	
		    	System.out.println(name +"   " + pass);
		    	
		    	if(username.equals(name) && pass.equals(password)){
		    		
				    		isValid = true;
				}
				    	
				        
				        
			}
		    
		    
   				    			    
		    // Provide a message when processing is complete.
		   

		}
		catch (ClassNotFoundException cnfe)  
        {

            System.out.println("ClassNotFoundException " +
                               cnfe.getMessage());
        }
        catch (Exception e)
        {
            System.out.println("Exception " + e.getMessage());
            e.printStackTrace();
        }
        finally
        {
            try
            {
                // Close resources.
                if (null != connection) connection.close();
                if (null != statement) statement.close();
                if (null != resultSet) resultSet.close();
            }
            catch (SQLException sqlException)
            {
                // No additional action if close() statements fail.
            }
        }
		
		return isValid;
	}

	public void saveDifficulty(String username, int difficulty) {
		// Connection string for your SQL Database server.
				// Change the values assigned to your_server, 
				// your_user@your_server,
				// and your_password.
				String connectionString = 
				    "jdbc:sqlserver://cwknc6b9er.database.windows.net:1433;" +
				    "database=MortarCombatDB;user=firat@cwknc6b9er;password={Mortar_123};" +
				    "encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

				// The types for the following variables are
				// defined in the java.sql library.
				Connection connection = null;  // For making the connection
				Statement statement = null;    // For the SQL statement
				
				int resultSet;    // For the result set, if applicable
				

				try
				{
				    // Ensure the SQL Server driver class is available.
				    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

				    // Establish the connection.
				    connection = DriverManager.getConnection(connectionString);

				    // Define the SQL string.
				    String sqlString = " UPDATE UserTable SET [Difficulty]='"+difficulty+"' WHERE [Name]='"+username+"'  ";
				   

				    // Use the connection to create the SQL statement.
				    statement = connection.createStatement();
				    

				    // Execute the statement.
				    resultSet = statement.executeUpdate(sqlString);
				    

				  
				   

				}
				catch (ClassNotFoundException cnfe)  
		        {

		            System.out.println("ClassNotFoundException " +
		                               cnfe.getMessage());
		        }
		        catch (Exception e)
		        {
		            System.out.println("Exception " + e.getMessage());
		            e.printStackTrace();
		        }
		        finally
		        {
		            try
		            {
		                // Close resources.
		                if (null != connection) connection.close();
		                if (null != statement) statement.close();
		                
		            }
		            catch (SQLException sqlException)
		            {
		                // No additional action if close() statements fail.
		            }
		        }
	}

	public void saveGame(String username, int currentLevel, int currentScore) {
		// Connection string for your SQL Database server.
		// Change the values assigned to your_server, 
		// your_user@your_server,
		// and your_password.
		String connectionString = 
		    "jdbc:sqlserver://cwknc6b9er.database.windows.net:1433;" +
		    "database=MortarCombatDB;user=firat@cwknc6b9er;password={Mortar_123};" +
		    "encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

		// The types for the following variables are
		// defined in the java.sql library.
		Connection connection = null;  // For making the connection
		Statement statement = null;    // For the SQL statement
		
		int resultSet;    // For the result set, if applicable
		

		try
		{
		    // Ensure the SQL Server driver class is available.
		    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

		    // Establish the connection.
		    connection = DriverManager.getConnection(connectionString);

		    // Define the SQL string.
		    String sqlString = " UPDATE UserTable SET [LastEpisode]='"+currentLevel+"', [Score]= '"+currentScore+"' WHERE [Name]='"+username+"'  ";
		   

		    // Use the connection to create the SQL statement.
		    statement = connection.createStatement();
		    

		    // Execute the statement.
		    resultSet = statement.executeUpdate(sqlString);
		    

		  
		   

		}
		catch (ClassNotFoundException cnfe)  
        {

            System.out.println("ClassNotFoundException " +
                               cnfe.getMessage());
        }
        catch (Exception e)
        {
            System.out.println("Exception " + e.getMessage());
            e.printStackTrace();
        }
        finally
        {
            try
            {
                // Close resources.
                if (null != connection) connection.close();
                if (null != statement) statement.close();
                
            }
            catch (SQLException sqlException)
            {
                // No additional action if close() statements fail.
            }
        }
	}

	private LevelWorld createLevelData(int currentLevel) throws IOException {
		
		
		JFrame frame = new JFrame();
        frame.setSize(300,300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

        KeyListener s;

        try {
                AudioInputStream mortarAudio = AudioSystem.getAudioInputStream(new File("//mortarcombat//Sounds//mortar_n.wav"));
                //AudioInputStream mortarAudio = AudioSystem.getAudioInputStream(new File("//mortarcombat//Sounds//22-AudioTrack 22.wav"));
                //
                //Audios will be found and added to objects
                //
        }
        
        catch(UnsupportedAudioFileException uae) {
                System.out.println(uae);
        }
        catch(IOException ioe) {
                System.out.println(ioe);
        }
        catch(LineUnavailableException lua) {
                System.out.println(lua);
        }


		
		/*if(currentLevel == 1)
		{
			GameObject[][] levelData = new GameObject[2][23];
			Jb2dJson json = new Jb2dJson();
			StringBuilder errorMsg = new StringBuilder();

			World world = json.readFromFile("src/Mortar_Combat_1.json", errorMsg);
			levelData[0][0] = new UnmovableBrick( json.getBodyByName("topWall"), "assets/enemy.png", null);
			levelData[0][1] = new UnmovableBrick( json.getBodyByName("bottomWall"), "assets/enemy.png", null);
			levelData[0][2] = new UnmovableBrick( json.getBodyByName("rightWall"), "assets/enemy.png", null);
			levelData[0][3] = new UnmovableBrick( json.getBodyByName("leftWall"), "assets/enemy.png", null);
			levelData[0][4] = new UnmovableBrick( json.getBodyByName("static1"), "assets/enemy.png", null);
			levelData[0][5] = new UnmovableBrick( json.getBodyByName("static2"), "assets/enemy.png", null);
			levelData[0][6] = new UnmovableBrick( json.getBodyByName("static3"), "assets/enemy.png", null);
			levelData[0][7] = new UnmovableBrick( json.getBodyByName("static4"), "assets/enemy.png", null);
			levelData[0][8] = new UnmovableBrick( json.getBodyByName("static5"), "assets/enemy.png", null);
			levelData[0][9] = new UnmovableBrick( json.getBodyByName("static6"), "assets/enemy.png", null);
			levelData[0][10] = new UnmovableBrick( json.getBodyByName("static7"), "assets/enemy.png", null);
			levelData[0][11] = new UnmovableBrick( json.getBodyByName("static8"), "assets/enemy.png", null);
			levelData[0][12] = new UnmovableBrick( json.getBodyByName("static9"), "assets/enemy.png", null);
			levelData[0][13] = new UnmovableBrick( json.getBodyByName("static10"), "assets/enemy.png", null);
			levelData[0][14] = new UnmovableBrick( json.getBodyByName("static11"), "assets/enemy.png", null);
			levelData[0][15] = new UnmovableBrick( json.getBodyByName("static12"), "assets/enemy.png", null);
			levelData[0][16] = new UnmovableBrick( json.getBodyByName("static13"), "assets/enemy.png", null);
			levelData[0][17] = new UnmovableBrick( json.getBodyByName("static14"), "assets/enemy.png", null);
			levelData[0][18] = new UnmovableBrick( json.getBodyByName("static15"), "assets/enemy.png", null);
			levelData[0][19] = new MovableBrick( json.getBodyByName("kinematic1"), "assets/enemy.png", null);
			levelData[0][20] = new MovableBrick( json.getBodyByName("kinematic2"), "assets/enemy.png", null);
			levelData[0][21] = new MovableBrick( json.getBodyByName("kinematic3"), "assets/enemy.png", null);
			levelData[0][22] = new MovableBrick( json.getBodyByName("dynamic1"), "assets/enemy.png", null);
			levelData[1][0] = new StandardEnemy( json.getBodyByName("enemy1"), "assets/enemy.png", null);
			levelData[1][1] = new StandardEnemy( json.getBodyByName("enemy2"), "assets/enemy.png", null);
			levelData[1][2] = new StandardEnemy( json.getBodyByName("enemy3"), "assets/enemy.png", null);
			world.setGravity( new Vec2( 0, 10 ) );
			return new LevelWorld( levelData, world );
		}
		if(currentLevel == 2)
		{
			GameObject[][] levelData = new GameObject[2][43];
			Jb2dJson json = new Jb2dJson();
			StringBuilder errorMsg = new StringBuilder();
			
			World world = json.readFromFile("src/Mortar_Combat_1.json", errorMsg);
			levelData[0][0] = new UnmovableBrick( json.getBodyByName("topWall"), "assets/enemy.png", null);
			levelData[0][1] = new UnmovableBrick( json.getBodyByName("bottomWall"), "assets/enemy.png", null);
			levelData[0][2] = new UnmovableBrick( json.getBodyByName("rightWall"), "assets/enemy.png", null);
			levelData[0][3] = new UnmovableBrick( json.getBodyByName("leftWall"), "assets/enemy.png", null);
			levelData[0][4] = new UnmovableBrick( json.getBodyByName("static1"), "assets/enemy.png", null);
			levelData[0][5] = new UnmovableBrick( json.getBodyByName("static2"), "assets/enemy.png", null);
			levelData[0][6] = new UnmovableBrick( json.getBodyByName("static3"), "assets/enemy.png", null);
			levelData[0][7] = new UnmovableBrick( json.getBodyByName("static4"), "assets/enemy.png", null);
			levelData[0][8] = new UnmovableBrick( json.getBodyByName("static5"), "assets/enemy.png", null);
			levelData[0][9] = new UnmovableBrick( json.getBodyByName("static6"), "assets/enemy.png", null);
			levelData[0][10] = new UnmovableBrick( json.getBodyByName("static7"), "assets/enemy.png", null);
			levelData[0][11] = new UnmovableBrick( json.getBodyByName("static8"), "assets/enemy.png", null);
			levelData[0][12] = new UnmovableBrick( json.getBodyByName("static9"), "assets/enemy.png", null);
			levelData[0][13] = new UnmovableBrick( json.getBodyByName("static10"), "assets/enemy.png", null);
			levelData[0][14] = new UnmovableBrick( json.getBodyByName("static11"), "assets/enemy.png", null);
			levelData[0][15] = new UnmovableBrick( json.getBodyByName("static12"), "assets/enemy.png", null);
			levelData[0][16] = new UnmovableBrick( json.getBodyByName("static13"), "assets/enemy.png", null);
			levelData[0][17] = new UnmovableBrick( json.getBodyByName("static14"), "assets/enemy.png", null);
			levelData[0][18] = new UnmovableBrick( json.getBodyByName("static15"), "assets/enemy.png", null);
			levelData[0][19] = new UnmovableBrick( json.getBodyByName("static16"), "assets/enemy.png", null);
			levelData[0][20] = new UnmovableBrick( json.getBodyByName("static17"), "assets/enemy.png", null);
			levelData[0][21] = new UnmovableBrick( json.getBodyByName("static18"), "assets/enemy.png", null);
			levelData[0][22] = new UnmovableBrick( json.getBodyByName("static19"), "assets/enemy.png", null);
			levelData[0][23] = new UnmovableBrick( json.getBodyByName("static20"), "assets/enemy.png", null);
			levelData[0][24] = new UnmovableBrick( json.getBodyByName("static21"), "assets/enemy.png", null);
			levelData[0][25] = new UnmovableBrick( json.getBodyByName("static22"), "assets/enemy.png", null);
			levelData[0][26] = new UnmovableBrick( json.getBodyByName("static23"), "assets/enemy.png", null);
			levelData[0][27] = new UnmovableBrick( json.getBodyByName("static24"), "assets/enemy.png", null);
			levelData[0][28] = new UnmovableBrick( json.getBodyByName("static25"), "assets/enemy.png", null);
			levelData[0][29] = new UnmovableBrick( json.getBodyByName("static26"), "assets/enemy.png", null);
			levelData[0][30] = new UnmovableBrick( json.getBodyByName("static27"), "assets/enemy.png", null);
			levelData[0][31] = new MovableBrick( json.getBodyByName("dynamic1"), "assets/enemy.png", null);
			levelData[0][32] = new MovableBrick( json.getBodyByName("dynamic2"), "assets/enemy.png", null);
			levelData[0][33] = new MovableBrick( json.getBodyByName("dynamic3"), "assets/enemy.png", null);
			levelData[0][34] = new MovableBrick( json.getBodyByName("dynamic4"), "assets/enemy.png", null);
			levelData[0][35] = new MovableBrick( json.getBodyByName("dynamic5"), "assets/enemy.png", null);
			levelData[0][36] = new MovableBrick( json.getBodyByName("dynamic6"), "assets/enemy.png", null);
			levelData[0][37] = new MovableBrick( json.getBodyByName("dynamic7"), "assets/enemy.png", null);
			levelData[0][38] = new MovableBrick( json.getBodyByName("dynamic8"), "assets/enemy.png", null);
			levelData[0][39] = new MovableBrick( json.getBodyByName("dynamic9"), "assets/enemy.png", null);
			levelData[0][40] = new MovableBrick( json.getBodyByName("dynamic10"), "assets/enemy.png", null);
			levelData[0][41] = new MovableBrick( json.getBodyByName("dynamic11"), "assets/enemy.png", null);
			levelData[0][42] = new MovableBrick( json.getBodyByName("dynamic12"), "assets/enemy.png", null);
			levelData[1][0] = new StandardEnemy( json.getBodyByName("enemy1"), "assets/enemy.png", null);
			levelData[1][1] = new StandardEnemy( json.getBodyByName("enemy2"), "assets/enemy.png", null);
			levelData[1][2] = new StandardEnemy( json.getBodyByName("enemy3"), "assets/enemy.png", null);
			levelData[1][3] = new StandardEnemy( json.getBodyByName("enemy4"), "assets/enemy.png", null);
			world.setGravity( new Vec2( 0, 10 ) );
			return new LevelWorld( levelData, world );
		}
		if(currentLevel == 3)
		{
			GameObject[][] levelData = new GameObject[2][30];
			Jb2dJson json = new Jb2dJson();
			StringBuilder errorMsg = new StringBuilder();

			World world = json.readFromFile("src/Mortar_Combat_1.json", errorMsg);
			levelData[0][0] = new UnmovableBrick( json.getBodyByName("topWall"), "assets/enemy.png", null);
			levelData[0][1] = new UnmovableBrick( json.getBodyByName("bottomWall"), "assets/enemy.png", null);
			levelData[0][2] = new UnmovableBrick( json.getBodyByName("rightWall"), "assets/enemy.png", null);
			levelData[0][3] = new UnmovableBrick( json.getBodyByName("leftWall"), "assets/enemy.png", null);
			levelData[0][4] = new UnmovableBrick( json.getBodyByName("static1"), "assets/enemy.png", null);
			levelData[0][5] = new UnmovableBrick( json.getBodyByName("static2"), "assets/enemy.png", null);
			levelData[0][6] = new UnmovableBrick( json.getBodyByName("static3"), "assets/enemy.png", null);
			levelData[0][7] = new UnmovableBrick( json.getBodyByName("static4"), "assets/enemy.png", null);
			levelData[0][8] = new UnmovableBrick( json.getBodyByName("static5"), "assets/enemy.png", null);
			levelData[0][9] = new UnmovableBrick( json.getBodyByName("static6"), "assets/enemy.png", null);
			levelData[0][10] = new UnmovableBrick( json.getBodyByName("static7"), "assets/enemy.png", null);
			levelData[0][11] = new UnmovableBrick( json.getBodyByName("static8"), "assets/enemy.png", null);
			levelData[0][12] = new UnmovableBrick( json.getBodyByName("static9"), "assets/enemy.png", null);
			levelData[0][13] = new UnmovableBrick( json.getBodyByName("static10"), "assets/enemy.png", null);
			levelData[0][14] = new UnmovableBrick( json.getBodyByName("static11"), "assets/enemy.png", null);
			levelData[0][15] = new UnmovableBrick( json.getBodyByName("static12"), "assets/enemy.png", null);
			levelData[0][16] = new UnmovableBrick( json.getBodyByName("static13"), "assets/enemy.png", null);
			levelData[0][17] = new UnmovableBrick( json.getBodyByName("static14"), "assets/enemy.png", null);
			levelData[0][18] = new UnmovableBrick( json.getBodyByName("static15"), "assets/enemy.png", null);
			levelData[0][19] = new UnmovableBrick( json.getBodyByName("static16"), "assets/enemy.png", null);
			levelData[0][20] = new UnmovableBrick( json.getBodyByName("static17"), "assets/enemy.png", null);
			levelData[0][21] = new UnmovableBrick( json.getBodyByName("static18"), "assets/enemy.png", null);
			levelData[0][22] = new MovableBrick( json.getBodyByName("kinematic1"), "assets/enemy.png", null);
			levelData[0][23] = new MovableBrick( json.getBodyByName("kinematic2"), "assets/enemy.png", null);
			levelData[0][24] = new MovableBrick( json.getBodyByName("kinematic3"), "assets/enemy.png", null);
			levelData[0][25] = new MovableBrick( json.getBodyByName("kinematic4"), "assets/enemy.png", null);
			levelData[0][26] = new MovableBrick( json.getBodyByName("dynamic1"), "assets/enemy.png", null);
			levelData[0][27] = new MovableBrick( json.getBodyByName("dynamic2"), "assets/enemy.png", null);
			levelData[0][28] = new MovableBrick( json.getBodyByName("dynamic3"), "assets/enemy.png", null);
			levelData[0][29] = new MovableBrick( json.getBodyByName("dynamic4"), "assets/enemy.png", null);
			levelData[1][0] = new StandardEnemy( json.getBodyByName("enemy1"), "assets/enemy.png", null);
			levelData[1][1] = new StandardEnemy( json.getBodyByName("enemy2"), "assets/enemy.png", null);
			levelData[1][2] = new StandardEnemy( json.getBodyByName("enemy3"), "assets/enemy.png", null);
			levelData[1][3] = new StandardEnemy( json.getBodyByName("enemy4"), "assets/enemy.png", null);
			levelData[1][4] = new StandardEnemy( json.getBodyByName("enemy5"), "assets/enemy.png", null);
			world.setGravity( new Vec2( 0, 10 ) );
			return new LevelWorld( levelData, world );
		}
		if(currentLevel == 4)
		{
			GameObject[][] levelData = new GameObject[2][21];
			Jb2dJson json = new Jb2dJson();
			StringBuilder errorMsg = new StringBuilder();

			World world = json.readFromFile("src/Mortar_Combat_1.json", errorMsg);
			levelData[0][0] = new UnmovableBrick( json.getBodyByName("topWall"), "assets/enemy.png", null);
			levelData[0][1] = new UnmovableBrick( json.getBodyByName("bottomWall"), "assets/enemy.png", null);
			levelData[0][2] = new UnmovableBrick( json.getBodyByName("rightWall"), "assets/enemy.png", null);
			levelData[0][3] = new UnmovableBrick( json.getBodyByName("leftWall"), "assets/enemy.png", null);
			levelData[0][4] = new UnmovableBrick( json.getBodyByName("static1"), "assets/enemy.png", null);
			levelData[0][5] = new UnmovableBrick( json.getBodyByName("static2"), "assets/enemy.png", null);
			levelData[0][6] = new UnmovableBrick( json.getBodyByName("static3"), "assets/enemy.png", null);
			levelData[0][7] = new UnmovableBrick( json.getBodyByName("static4"), "assets/enemy.png", null);
			levelData[0][8] = new UnmovableBrick( json.getBodyByName("static5"), "assets/enemy.png", null);
			levelData[0][9] = new UnmovableBrick( json.getBodyByName("static6"), "assets/enemy.png", null);
			levelData[0][10] = new UnmovableBrick( json.getBodyByName("static7"), "assets/enemy.png", null);
			levelData[0][11] = new UnmovableBrick( json.getBodyByName("static8"), "assets/enemy.png", null);
			levelData[0][12] = new UnmovableBrick( json.getBodyByName("static9"), "assets/enemy.png", null);
			levelData[0][13] = new UnmovableBrick( json.getBodyByName("static10"), "assets/enemy.png", null);
			levelData[0][14] = new MovableBrick( json.getBodyByName("kinematic1"), "assets/enemy.png", null);
			levelData[0][15] = new MovableBrick( json.getBodyByName("kinematic2"), "assets/enemy.png", null);
			levelData[0][16] = new MovableBrick( json.getBodyByName("kinematic3"), "assets/enemy.png", null);
			levelData[0][17] = new MovableBrick( json.getBodyByName("dynamic1"), "assets/enemy.png", null);
			levelData[0][18] = new MovableBrick( json.getBodyByName("dynamic2"), "assets/enemy.png", null);
			levelData[0][19] = new MovableBrick( json.getBodyByName("dynamic3"), "assets/enemy.png", null);
			levelData[0][20] = new MovableBrick( json.getBodyByName("dynamic4"), "assets/enemy.png", null);
			levelData[1][0] = new StandardEnemy( json.getBodyByName("enemy1"), "assets/enemy.png", null);
			levelData[1][1] = new StandardEnemy( json.getBodyByName("enemy2"), "assets/enemy.png", null);
			levelData[1][2] = new StandardEnemy( json.getBodyByName("enemy3"), "assets/enemy.png", null);
			world.setGravity( new Vec2( 0, 10 ) );
			return new LevelWorld( levelData, world );
		}*/

		if(currentLevel == 5)
		{
			GameObject[][] levelData = new GameObject[1][];
			levelData[0] = new GameObject[2];
			//levelData[1] = new GameObject[4];
			Jb2dJson json = new Jb2dJson();
			
			StringBuilder errorMsg = new StringBuilder();

			World world = json.readFromFile("src/Mortar Combat 5.json", errorMsg);
			//int a = world.WORLD_POOL_SIZE;
			//levelData[0][0] = new UnmovableBrick( json.getBodyByName("leftUpperCorner"), json.getImageByName("image0"), null);
			//levelData[0][1] = new UnmovableBrick( json.getBodyByName("rightLowerCorner"), json.getImageByName("image0"), null);
			//levelData[0][0] = new UnmovableBrick( json.getBodyByName("topWall"), json.getImageByName("image0"), null);
			//levelData[0][1] = new UnmovableBrick( json.getBodyByName("bottomWall"), json.getImageByName("brick3"), null);
			//levelData[0][2] = new UnmovableBrick( json.getBodyByName("rightWall"), json.getImageByName("image0"), null);
			//levelData[0][3] = new UnmovableBrick( json.getBodyByName("leftWall"), json.getImageByName("image0"), null);
			//levelData[0][0] = new UnmovableBrick( json.getBodyByName("static1"), json.getImageByName("groundR"), null);
			//levelData[0][1] = new UnmovableBrick( json.getBodyByName("static2"), json.getImageByName("groundL"), null);
			//levelData[0][2] = new UnmovableBrick( json.getBodyByName("static3"), json.getImageByName("groundM"), null);
			//levelData[0][0] = new UnmovableBrick( json.getBodyByName("static4"), json.getImageByName("brick2"), null);
			levelData[0][1] = new UnmovableBrick( json.getBodyByName("static5"), json.getImageByName("brick3"), null);
			//levelData[0][2] = new MovableBrick( json.getBodyByName("kinematic1"), json.getImageByName("movingBrick"), null);
			levelData[0][0] = new MovableBrick( json.getBodyByName("dynamic1"), json.getImageByName("brick1"), null);
			//levelData[1][0] = new StandardEnemy( json.getBodyByName("enemy1"), json.getImageByName("enemy"), null);
			//levelData[1][1] = new StandardEnemy( json.getBodyByName("enemy2"), json.getImageByName("enemy"), null);
			//levelData[1][2] = new StandardEnemy( json.getBodyByName("enemy3"), json.getImageByName("enemy"), null);
			//levelData[1][3] = new StandardEnemy( json.getBodyByName("enemy4"), json.getImageByName("enemy"), null);
			
			world.setGravity( new Vec2( 0, 100 ) );
			return new LevelWorld( levelData, world );
		}
		return null;
		
	}
}
